#include"Door.h"
	
Door :: Door (){
	DId = 200;
	PassWord = 000000;
	StressLvl = 0;
	InfraredLvl = 0;
	IsClose = true;
	SensorStress temp1(DId);
	DoStrssSensor = temp1;
	SensorInfrared temp2(DId);
	DoInfraSensor = temp2;
	SensorOpenClose temp3(DId);
	DoOpClSensor = temp3;
}

Door :: Door(int &_DId, string &_PassWord, int &_StressLvl, int &_InfraredLvl, bool _IsClose){
	if(_DId >=200){
	DId = _DId;
	PassWord = _PassWord;
	StressLvl = _StressLvl;
	InfraredLvl = _InfraredLvl;
	IsClose = _IsClose;
	SensorStress temp1(DId);
	DoStrssSensor = temp1;
	SensorInfrared temp2(DId);
	DoInfraSensor = temp2;
	SensorOpenClose temp3(DId);
	DoOpClSensor = temp3;
	}
	else
		cout<<"The Id of door should above 200 !"<<endl;
}

void Door :: DoorSimulation(){
	cout<<"Please enter the door's id(must one integer above 200): ";
	int _DId;
	cin>>_DId;
	cout<<"Please enter the password of the door(six numbers can be good):";
	string _PassWord;
	cin>>_PassWord;
	cout<<"Please enter the stress level of the door(an integer): ";
	int _StressLvl;
	cin>>_StressLvl;
	cout<<"Please enter the infrared level of the door(an integer): ";
	int _InfraredLvl;
	cin>>_InfraredLvl;
	cout<<"Please enter the state of the door(0 stands for close, 1 stands for open): "
	bool OpenClose;
	cin>>OpenClose;
	cout<<"Please set the parameter of the door's sensors(the first is stresspoint, next is infraredpoint) :";
	int StressPoint, InfraredPoint;
	cin>>StressPoint>>InfraredPoint;
	if(_DId >= 200){
		DId = _DId;
		PassWord = _PassWord;
		StressLvl = _StressLvl;
		InfraredLvl = _InfraredLvl;
		IsClose = OpenClose;
		SensorStress temp1(DId, StressPoint);
		DoStrssSensor = temp1;
		SensorInfrared temp2(DId, InfraredPoint);
		DoInfraSensor = temp2;
		SensorOpenClose temp3(DId);
		DoOpClSensor = temp3;
	}
	else
		cout<<"The Id of door should above 200 !"<<endl;
}

void  Door :: SetStressLvl(int &_StressLvl){
	StressLvl = _StressLvl;
}

void Door:: SetInfraredLvl(int &_InfraredLvl){
	InfraredLvl = _InfraredLvl;
}

void Door :: ChangePssWord(string &NewPssWord){
	PassWord = NewPssWord;
}

void Door :: OpenDoor(string &InputData){
	if(InputData == PassWord) 
		IsClose = false;
}

void Door :: CloseDoor(){
	if(IsClose == false)
		IsClose = true;
}

List<Msg> Door :: GetMsg(){
	List<Msg> temp;
	cout<<"Please enter the door password:";
	string InputData;
	cin>>InputData;
	if(InputData != PassWord){		
		Msg Receive;
		DoStrssSensor.CaptureStress(StressLvl);
		Receive = DoStrssSensor.ReturnMsg();
		if(Receive.MId != ExcptNone)  temp.Insert(temp.GetSize(), Receive);
		DoInfraSensor.CaptureInfrared(InfraredLvl);
		Receive = DoInfraSensor.ReturnMsg();
		if(Receive.MId != ExcptNone)  temp.Insert(temp.GetSize(), Receive);
		DoOpClSensor.CaptureOpCls(IsClose);
		Receive = DoOpClSensor.ReturnMsg();
		if(Receive.MId != ExcptNone)  temp.Insert(temp.GetSize(), Receive);
	}
	return temp;
}

bool Door :: operator ==(const Door &SampleDoor){
	return DId == SampleDoor.DId;
}

bool Door :: operator !=(const Door &SampleDoor){
	return !(DId == SampleDoor.DId);
}